const router = require('koa-router')();
const {register, login, editUserInfo, getUserList, getMatchList, getUserDetail, getChess} = require('../service/userService');

router.prefix('/users');

router.get('/', function (ctx, next) {
    ctx.body = 'this is a users response!'
});

router.post('/login', async function (ctx, next) {
    ctx.body = await login(ctx.request.body, ctx);
});

router.post('/register', async function (ctx, next) {
    ctx.body = await register(ctx.request.body, ctx);
});
//获取用户列表
router.get('/list', async function (ctx, next) {
    ctx.body = await getUserList(ctx);
});
//获取用户信息
router.get('/info', async function (ctx, next) {
    ctx.body = await getUserDetail(ctx);
});
//编辑用户信息
router.post('/info', async function (ctx, next) {
    ctx.body = await editUserInfo(ctx.request.body, ctx);
});
//获取比赛列表
router.get('/match', async function (ctx, next) {
    ctx.body = await getMatchList(ctx);
});

//获取比赛信息
router.get('/chess', async function (ctx, next) {
    ctx.body = await getChess(ctx);
});

module.exports = router;
